home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / vlclass.exe / CHGSER.CPP < prev    next >
C/C++ Source or Header  |  1991-11-20  |  2KB  |  92 lines

  1. /*
  2.    CHGSER.CPP
  3.    By Tom Astin 73407,3427
  4.    Copyright 1991
  5.    Use as is.
  6.    Not fully tested.
  7.    Author not responsible for any negative results.
  8.    Program to test VolLabel class - please see notes in VOLLAB.CPP before
  9.    using.
  10.    *** USE WITH CAUTION ***
  11.    This program modifies the boot sector which contains the volume ID.
  12.    Only tested on small/floppy media. Modification using special parameter
  13.      block for read/write most likely neccessary for larger media (>=32mb).
  14.    Will abort on dos version < 4.
  15. */
  16.  
  17. #include <iostream.h>
  18. #include <iomanip.h>
  19. #include <stdlib.h>
  20. #include <ctype.h>
  21. #include "vollab.h"
  22.  
  23. void ErrorMsg(char *msg)
  24. {
  25.     cout << msg << endl << endl;
  26.     exit(1);
  27. }
  28.  
  29. int sertol(char *szSer, unsigned long *nSer)
  30. {
  31.     char valid[]="0123456789ABCDEF";
  32.  
  33.     if (strlen(strupr(szSer))!=9 || szSer[4]!='-' ||
  34.         strspn(szSer,valid)<4 || strspn(&szSer[5],valid)<4)
  35.         return 0;
  36.     *nSer=strtol(szSer,NULL,16) << 16;
  37.     *nSer=*nSer | strtol(&szSer[5],NULL,16);
  38.     return 1;
  39. }
  40.  
  41. int main(int argc, char *argv[])
  42. {
  43.     VolLabel vl;
  44.     unsigned long VolID;
  45.     char szVolID[10], cDrive;
  46.     unsigned char nDrive;
  47.  
  48.     cout << "Volume ID changer." << endl << endl;
  49.  
  50.     if (_osmajor<4)
  51.         ErrorMsg("Cannot use with DOS version less than 4.00");
  52.  
  53.     if (argc>2)
  54.         ErrorMsg("Invalid number of parameters. CHGSER [d:]");
  55.  
  56.     if (argc==2) {
  57.         cDrive=toupper(argv[1][0]);
  58.         if (strlen(argv[1])>2 || argv[1][1]!=':' || cDrive<'A' || cDrive>'Z')
  59.             ErrorMsg("Invalid parameter.");
  60.         nDrive='A'-cDrive+1;
  61.     }
  62.     else {
  63.         nDrive=vl.GetDisk();
  64.         cDrive='A'+nDrive;
  65.         ++nDrive;
  66.     }
  67.  
  68.     VolID=vl.GetSerial(nDrive);
  69.     cout.setf(ios::uppercase);
  70.     cout << "Current serial # for " << cDrive << " is ";
  71.     cout << hex << setfill('0') << setw(4)
  72.          << ((unsigned) (VolID >> 16)) << '-'
  73.          << setfill('0') << setw(4)
  74.          << ((unsigned) VolID) << endl;
  75.     cout << "Enter new serial # (NNNN-NNNN):";
  76.     cin.get(szVolID,sizeof(szVolID));
  77.     cin.ignore();
  78.     if (sertol(szVolID,&VolID)) {
  79.         if (vl.SetSerial(nDrive,VolID))
  80.             cout << "Volume ID changed." << endl;
  81.         else
  82.             ErrorMsg("Error while chaning volume ID.");
  83.     }
  84.     else
  85.         if (strlen(szVolID)==0)
  86.             cout << "Volume ID not changed." << endl;
  87.         else
  88.             ErrorMsg("Error with volume ID input.");
  89.     cout << endl;
  90.     return 0;
  91. }
  92.